import cv2
import numpy as np
import torch
import os

'''
这个东西没什么用
'''


def __load_annotations(path,save_label_file):
    truth = {}
    with open(path, 'r', encoding='utf-8') as f:
        for line in f.readlines():
            line = line.rstrip('\n')
            data = line.split(' ')
            if len(data)==1:
                continue
            truth[data[0]] = []
            h, w, _ = cv2.imread(data[0]).shape
            for i in data[1:]:
                l = [int(float(j)) for j in i.split(',')]
                truth[data[0]].append(l)
    torch.save(truth,save_label_file)
    return truth

if __name__ == '__main__':
    save_label_file=r'D:\python\upload\learn_yolov4_and_yolov5\data\\train.cache'
    laebl_file = r'D:\python\Aclass\1\myselfV1\data\\train_annotation.txt'

    if os.path.isfile(save_label_file):
        cache = torch.load(save_label_file)  # load
        print('load_data')
    else:
        cache = __load_annotations(laebl_file,save_label_file)  # cache
        print('save_data')
    print(cache)
